/**
 * May 17, 20148:32:00 AM
 */
package elitech.vietnam.copyweatherfashion.fragments.settings;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import elitech.vietnam.copyweatherfashion.MainActivity;
import elitech.vietnam.copyweatherfashion.R;
import elitech.vietnam.copyweatherfashion.utilities.Utilities;

/**
 * @author Cong
 */
public class FriendListFragment extends Fragment {

	public static final String	TAG_FOLLOW		= "TAG_FOLLOW";
	public static final String	TAG_FOLLOWING	= "TAG_FOLLOWING";
	
	public static final String	ARG_RESUMETAB	= "ARG_RESUMETAB";

	MainActivity				mActivity;

	FragmentTabHost				mTabHost;

	public FriendListFragment() {
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mActivity = (MainActivity) getActivity();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.settings_friendlist, container, false);

		mTabHost = (FragmentTabHost) view.findViewById(R.id.friendlist_tabhost);

		mTabHost.setup(mActivity, getChildFragmentManager(), R.id.friendlist_tabcontent);
		mTabHost.addTab(
				mTabHost.newTabSpec(TAG_FOLLOW).setIndicator(
						createTabView(R.drawable.meadded_s, R.drawable.meadded_d,
								getString(R.string.setting_friend_list_tui_them_ban))),
				FriendListContentFragment.class, FriendListContentFragment.newArs(TAG_FOLLOW));
		mTabHost.addTab(
				mTabHost.newTabSpec(TAG_FOLLOWING).setIndicator(
						createTabView(R.drawable.addedme_s, R.drawable.addedme_d,
								getString(R.string.setting_friend_list_ban_them_tui))),
				FriendListContentFragment.class, FriendListContentFragment.newArs(TAG_FOLLOWING));

		return view;
	}

	private View createTabView(int selected, int normal, String title) {
		View view = LayoutInflater.from(mActivity).inflate(R.layout.styler_tab, null);
		TextView mTitle = (TextView) view.findViewById(R.id.stylertab_txtText);
		ImageView mImage = (ImageView) view.findViewById(R.id.stylertab_imgImage);
		Drawable drawable = Utilities.getTabDrawable(mActivity, selected, normal);
		mImage.setImageDrawable(drawable);
		mTitle.setText(title);
		return view;
	}
	
	@Override
	public void onStart() {
		super.onStart();
		mActivity.mBtnCamera.setVisibility(View.GONE);
		mActivity.mBtnBack.setVisibility(View.VISIBLE);
		mActivity.mBtnEdit.setVisibility(View.GONE);
		mActivity.mBtnNotify.setVisibility(View.VISIBLE);
		if (getArguments()!=null && getArguments().getInt(ARG_RESUMETAB, 0) > 0)
			mTabHost.setCurrentTab(getArguments().getInt(ARG_RESUMETAB, 0));
	}
	
	@Override
	public void onDestroyView() {
		mActivity.mFriendList1.clear();
		mActivity.mFriendList2.clear();
		super.onDestroyView();
	}
}
